using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Collections;
using NovodexWrapper;

namespace marbletrack
{
    public abstract class PhysicsControlledObject
    {
        protected ModelClass model_;
        protected Matrix transform_;
        protected float density_;
        protected NxActor actor_;
        public NxActor Actor
        {
            get { return actor_; }
        }
        private Physics physics;
        protected Physics Physics
        {
            get { return physics; }
        }

        public PhysicsControlledObject()
        {
            physics = Game1.GetPhysics;
        }

        protected abstract void SetupVariables(Matrix transform);
       
        public Vector3 Position
        {
            //returns the object's current position
            get
            {
                return transform_.Translation;
            }
            //sets the actors position to a specified value and zeros the velocity
            set
            {
                actor_.setLinearVelocity(NxVec3.Zero);
                actor_.setGlobalPosition(MathConversion.ToNxVec3(value));
            }
        }

        //returns the velocity of the physics actor
        public Vector3 Velocity
        {
            get
            {
                return (MathConversion.ToVector3(this.actor_.getLinearVelocity()));
            }
        }

        // assigns the transform matrix (used for drawing) to the new value calculated by the physics engine
        public void Update()
        {
            transform_ = MathConversion.ToMatrix(actor_.getGlobalPose());
        }

        // Draw the ball using calculated transform matrix
        public virtual void Draw()
        {
            model_.Draw(transform_);
        }
    }
}
